package com.c.ctgproject.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.entity.MaterialDetailEntity
import com.c.ctgproject.utils.MyLog
import com.c.ctgproject.utils.handlerNull

/**
 * 作者:LiBW
 * 创建日期: 2020/9/7
 * 描述:物料详情列表适配器
 */
class MaterialDetailListAdapter(private val context: Context, private val mList: List<MaterialDetailEntity.DataBean.ListBean>) : RecyclerView.Adapter<MaterialDetailListAdapter.ViewHolder>() {
    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val mMaterialNameTV: TextView = itemView.findViewById(R.id.mPartNameTV)
        val mTimeTV: TextView = itemView.findViewById(R.id.mTimeTV)
        val mWeightTV: TextView = itemView.findViewById(R.id.mWeightTV)
        val mPriceTV: TextView = itemView.findViewById(R.id.mPriceTV)
        val mPhoneNumTV: TextView = itemView.findViewById(R.id.mPhoneNumTV)
        val mPayMethodTV: TextView = itemView.findViewById(R.id.mPayMethodTV)
        val mPaidTV: TextView = itemView.findViewById(R.id.mPaidTV)
        val mBuyerTV: TextView = itemView.findViewById(R.id.mBuyerTV)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_material_detail_list, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = mList[position]
        holder.mMaterialNameTV.text = data.materialName.handlerNull()
        holder.mTimeTV.text = data.outTime.handlerNull()
        holder.mWeightTV.text = data.planSalesWeight.handlerNull()
        holder.mPriceTV.text = data.salesPrice.handlerNull()
        holder.mPhoneNumTV.text = data.phoneNumber.handlerNull()
        holder.mPayMethodTV.text = data.financialSettlementWay.handlerNull()
        holder.mBuyerTV.text = data.purchaser.handlerNull()
        MyLog.d("${data.isPayOff}")
        holder.mPaidTV.text = if (data.isPayOff == 1) "是" else "否"
    }
}